import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../config/const.dart';
import '../../widget/common_widget.dart';

class WebViewPage extends StatefulWidget {
  final Map? arguments;
  const WebViewPage({super.key, this.arguments});

  @override
  State<WebViewPage> createState() => _WebViewPageState();
}

class _WebViewPageState extends State<WebViewPage> {

  String title = '';
  String url = '';
  late WebViewController _webViewController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    title = widget.arguments?['title'] ?? '';
    url = widget.arguments?['url'] ?? 'https://www.listenleap.com';
    _webViewController  = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(defaultBgColor)
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onHttpError: (HttpResponseError error) {},
          onWebResourceError: (WebResourceError error) {},
          onNavigationRequest: (NavigationRequest request) {
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse(url));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: defaultBlackBgColor,
      // appBar: myAppBar(context, title??'',backgroundColor: defaultBgColor),
      body: Container(
        child: Column(
          children: [
            SizedBox(height: ScreenUtil().statusBarHeight + 40.w,),
            Container(
               padding: EdgeInsets.symmetric(horizontal: 30.w),
              child: myCustomCenterTitleAppBar(title??''),
            ),
            SizedBox(height: 10.w,),
            Expanded(child: WebViewWidget(
              controller: _webViewController,
            ))
          ],
        ),
      ),
    );
  }
}
